#!/usr/bin/python

import sys
import cgi
import pg


import cgitb

cgitb.enable()

#def checkInt(val):
#	try: int(val)
#	except: ValueEroor: return 0
#	else: return 1

def stdprintf(string=""):
        sys.stdout.write(string)
        sys.stdout.write('\n\n')
        sys.stdout.flush()

header = 'Content-Type: text/html'


#form = cgi.FieldStorage(keep_blank_values=true)
form = cgi.FieldStorage()
#action = form['actions'].value

password = ''
username = 'plesk'
db_name = 'plesk'
hostname = form['testset'].value

select_owner = 'SELECT DISTINCT a.account_id as id, a.company_name as user_name from accounts a, service_templates st where a.account_id = st.owner_id'

db = pg.connect(dbname = db_name, host =  hostname, user = username)

str = ""

for i in db.query(select_owner).dictresult():
	str += "<input type = 'radio' name = 'owner' value = %(id)s> %(user_name)s <br>" % i

#cur = db.cursor()
#cur.execute(select_owner)

#res = cur.fetchall()

#cur.close()
#db.close()



stdprintf(header)
stdprintf("<html><head><title>QA TOOLS</title></head><body>")
stdprintf("<form action = 'backup2.py' method = get>")

stdprintf(str)
#stdprintf("<input type = 'hidden' name = 'action' value = %s >" % action)
stdprintf("<input type='submit' value='>>Next>>'>")
stdprintf("</body></html>")

